package com.vortex.cloud.sample.easyexcel.nange.readexcel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.*;

/**
 * @author 王林
 * @version 1.0
 * @date 2021-10-08 周五
 * @time 8:31
 * @description
 */
public class ExcelTest {
    public static void main(String[] args) {
        List<Map<Integer, String>> list = new LinkedList<>();
        EasyExcel.read("G:\\easyexcel\\用户数据表.xls")
                .sheet()
                .registerReadListener(new AnalysisEventListener<Map<Integer, String>>() {

                    @Override
                    public void invoke(Map<Integer, String> integerStringMap, AnalysisContext analysisContext) {

                        list.add(integerStringMap);
                    }

                    @Override
                    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
                        //通知文件读取完毕
                        System.out.println("文件读取完毕!!!");
                    }
                }).doRead();
        for (Map<Integer, String> integerStringMap : list) {
            Set<Integer> keySet = integerStringMap.keySet();
            Iterator<Integer> iterator = keySet.iterator();
            while (iterator.hasNext()) {
                Integer key = iterator.next();
                System.out.print(key + ":" + integerStringMap.get(key) + ", ");
            }
            System.out.println("");
        }
    }
}
